<?php

function _edit_entry(){
	
	$html = <<<HTML
<div id="write-entry" class="manage-table">
    <form action="action.php?do=edit_entry%s" method="post">
        <table class="write-entry-table">
        <tr>
            <td>Tiêu đề</td>
            <td style="text-align:left"><input id="title" name="entry-title" type="text" value="%s" /></td>
            <td><input type="submit" value="Xác nhận" /></td>            
        </tr>
        <tr>
            <td colspan="4"><textarea id="textarea" name="entry-content" rows="20">%s</textarea></td>
        </tr>
        </table>                
    </form>
</div>
HTML;

	if ($_SESSION['id']==0){
		printf($html,'','','','');
	} else {
		$id = $_SESSION['id'];
		$result = mysql_query("SELECT * FROM entry WHERE entry_id='$id'");
		if (!mysql_num_rows($result)){
			$id = 0;			
			$title = '';
			$content = '';
		} else {
			$row = mysql_fetch_array($result);
			$title = $row['title'];
			$content = $row['content'];
		}
		printf($html,"&id=$id",$title,$content);	
	}
}

_edit_entry();

?>